/* Writed by ASKEY SH*/

#ifndef __HEADER_APPS_H__
#define __HEADER_APPS_H__

#define UPNP_VERSION_STRING "UPnP/1.1"
#define UPNP_VERSION	"20150721"
#define USE_IFACEWATCHER 1
#define USE_NETFILTER 1
#define SUPPORT_REMOTEHOST
#define MINIUPNPD_VERSION "1.8"

#define OS_NAME		"OpenWRT"
#define OS_VERSION	"OpenWRT/OpenWrt/Attitude_Adjustment__r40331_"
#define OS_URL		"http://www.openwrt.org/"

#define MINIUPNPD_SERVER_STRING	OS_VERSION " " UPNP_VERSION_STRING " MiniUPnPd/" MINIUPNPD_VERSION

/* Macro constant definitions. */
#define DYNDNS_UPT_URL "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
#define DYNDNS_UPT_URL_WILDCARD "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?wildcard=ON&hostname=[DOMAIN]&myip=[IP]"

#define CUSTOM_DYNDNS_UPT_URL "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?system=custom&hostname=[DOMAIN]&myip=[IP]"
#define CUSTOM_DYNDNS_UPT_URL_WILDCARD "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?wildcard=ON&system=custom&hostname=[DOMAIN]&myip=[IP]"

#define STATIC_DYNDNS_UPT_URL "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?system=statdns&hostname=[DOMAIN]&myip=[IP]"
#define STATIC_DYNDNS_UPT_URL_WILDCARD "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?wildcard=ON&system=statdns&hostname=[DOMAIN]&myip=[IP]"

#define ZONEEDIT_UPT_URL "http://[USERNAME]:[PASSWORD]@dynamic.zoneedit.com/auth/dynamic.html?host=[DOMAIN]&dnsto=[IP]"
#define ZONEEDIT_UPT_URL_WILDCARD "http://[USERNAME]:[PASSWORD]@dynamic.zoneedit.com/auth/dynamic.html?wildcard=ON&host=[DOMAIN]&dnsto=[IP]"

#define DNSOMATIC_UPT_URL "http://[USERNAME]:[PASSWORD]@updates.dnsomatic.com/nic/update?hostname=[DOMAIN]&myip=[IP]"
#define DNSOMATIC_UPT_URL_WILDCARD "http://[USERNAME]:[PASSWORD]@updates.dnsomatic.com/nic/update?wildcard=ON&hostname=[DOMAIN]&myip=[IP]" 

#define NO_IP_UPT_URL "http://[USERNAME]:[PASSWORD]@dynupdate.no-ip.com/nic/update?hostname=[DOMAIN]&myip=[IP]"
#define NO_IP_UPT_URL_WILDCARD "http://[USERNAME]:[PASSWORD]@dynupdate.no-ip.com/nic/update?wildcard=ON&hostname=[DOMAIN]&myip=[IP]" 

#define TUNNELBROKER_UPT_URL "http://[USERNAME]:[PASSWORD]@dyn.dns.he.net/nic/update?hostname=[DOMAIN]&myip=[IP]"

#define WINCO_DDNS_UPT_URL "http://[DOMAIN]:[PASSWORD]@members.ddns.com.br/nic/update?hostname=[DOMAIN]&myip=[IP]"
#define WINCO_DDNS_UPT_URL_WILDCARD "http://[DOMAIN]:[PASSWORD]@members.ddns.com.br/nic/update?wildcard=ON&hostname=[DOMAIN]&myip=[IP]"

#define DDNS_STATUS_DAT_FILE "/var/run/ddns/myddns_ipv4.dat"
#define DDNS_STATUS_ERR_FILE "/var/run/ddns/myddns_ipv4.err"
#define DDNS_STATUS_UPT_FILE "/var/run/ddns/myddns_ipv4.update"
/* Type definitions. */

/*tunnelbroker.net -> dns.he.net*/
static char *ddns_list[8] = {"dyndns.org", "custom.dyndns.org", "static.dyndns.org",  \
						"zoneedit.com", "dnsomatic.com", "no-ip.com", "dns.he.net", "ddns.com.br"};

/*By now we just support two kind of the ddns server dyndns.com and no-ip.com*/
#define DDNSSERVERNUM 2
static char *ddns_server[2]={"WWW.DYNDNS.COM","WWW.NO-IP.COM"};


struct echo_plus_st
{
	uint32_t test_gen_sn;
	uint32_t test_resp_sn;
	uint32_t recv_ts;
	uint32_t reply_ts;
	uint32_t fail_count;
	char data[0];
};

typedef struct a_waninfo{
    int status;
	char uptime[128];
    char l3_device[32];
    char proto[32];
    char device[32];
    char ipv4_address[32];
	char mask[32];
	char ipv6_address[128];
	char ipv6_mask[32];
	char ipv6_prefix_address[128];
	char ipv6_prefix_mask[64];
    char nexthop[128];
    char dns[512];
}a_winfo;

typedef struct a_dnsserverinfo{
    int statusdns1;
	int statusdns2;
    char type[32];
    char device[32];
    char dns1[128];
	char dns2[128];
}a_dnsinfo;

typedef struct a_wlan_associated_dev{
    char mac[32];
	char inf[32];
    char pathname[128];
}a_wlanAssociatedDev;

typedef struct a_dhcpv4_staticip_info{
    char mac[32];
	char ip[32];
}a_Dhcpv4StaticIpInfo;

typedef struct a_temperaturesensor_info{
    char Enable[32];
	char Status[32];
	char Reset[32];
	char ResetTime[64];
	char Name[32];
	char Value[32];
	char LastUpdate[64];
	char MinValue[32];
	char MinTime[64];
	char MaxValue[32];
	char MaxTime[64];
	char LowAlarmValue[32];
	char LowAlarmTime[64];
	char HighAlarmValue[32];
	char PollingInterval[32];
	char HighAlarmTime[64];
}a_TemperatureSensorInfo;

extern void get_time(char *name);
extern int udpecho(char *host, char *port, int num, int timeout, int size, int interval);
extern int upnpdevice();
extern int upnpservice();
extern char *parseTemplate(char *path, char *option);
extern void toSaveMapFile(char *mapfile, char *instance, char * value);
extern void getMfcInfo(char * name, char *value);
extern void getMfcInfo2(char * name, char *value);
extern void getProcessStatus(char *pid, char *value, char *string);
extern void getDevStatus(char *inf, char *key, char *value);
extern int get_DHCPv4_Server_Pool_1_Client_num();
extern void get_DHCPv4_Server_Pool_1_Client_info(char *key, char *value, char *string);
extern void get_DHCPv4_Server_Pool_1_Client_entry_path(char *key, char *value);
extern void get_Hosts_Host_info(char *key, char *value, char *string);
extern void get_DHCPv4_Server_Pool_1_StaticAddress_info(char *key, char *value, char *string);
extern void set_DHCPv4_Server_Pool_1_StaticAddress_info(char *key, char *value, char *string);
extern void get_DHCPv4_Server_Pool_1_ReservedAddresses_list(char *value);
extern void getWanInfo(char *inf, a_winfo *wandeviceinfo);
extern void getLanLowerLayerInterface(char *inf);
extern int checkEth0UpDown();
extern int checkDhcpServerOnOff();
extern int getWanMode(char *mode);
extern void getWanHigherLayerInterface (char *inf);
extern void getDnsServerInfo(a_dnsinfo *dnsinfo);
extern void getNetmask(char *inf, char *mask);
extern void getNetMtu(char *inf, char *mtu);
extern void getDeviceUpTime(char * finename, char * time);
extern void getFirewallLastChaneTime(char *time);
extern void getFirewallChainNumberOfEntries(char *value);
extern void getInterfaceLastChangeTime(char * time);
extern void getCpuUsage(char * value);
extern int get_all_process_num();
extern void get_Wlan_AssociatedDeviceInfo(a_wlanAssociatedDev *dev);
extern void getNextHopGwMac(char *mac);
extern void get_USBHostsDeviceInfo(char *busnum, char *value, char *key);
extern void get_USBHostsDeviceInfo2(char *busnum, char *value, char *key);
extern void get_ipv6_routing_info(char *key, char *value, char *string);
extern void getNeighRetransTimer(char *inf, char *value);
extern void getRtrSolicitationInterval(char *inf, char *value);
extern void getMaxRtrSolicitations(char *inf, char *value);
extern void getRouterAdvertisementOptionValue(char *value, char *type);
extern void get_Device_DHCPv6_Server_Pool_1_Client_address_by_mac(char *mac, char *value);
extern void check_Device_DHCP_Server_Pool_1_Client_address_active(char *family, char *ip, char *value);
extern void getDhcpv6IANAPreferredLifetime(char *value);
extern void getDhcpv6IANAValidLifetime(char *value);
extern void getCoreChipTemperatureStatus(int sector, a_TemperatureSensorInfo *temperatureSensorInfo);
extern void getWifiChipTemperatureStatus(int sector, a_TemperatureSensorInfo *temperatureSensorInfo);
extern int get_Device_DHCPv4_Server_Option_value(char *key, char *value);
extern long int getLocalTimeWithSeconds();
extern void getNSLookupDiagnosticsResultValue(int number, char *key, char *value);
extern int RadioNumberCheck(char *p);
extern int getSSIDuciConfig(char *p, char *buff, char *option);
extern int getSSIDuciConfig2(char *p, char *buff, char *option);
extern int rewrite_portmaping_entry(char *option, char *value, char *ExternalPort);
extern int setwanhttpsacs(char *mischttpsport, char *lanip, char* lanport);
extern int setwanhttpacs(char *mischttpsport, char *lanip, char* lanport);
extern int disablewanacs();
extern int getlanip(char* val);
extern int doRemoteAccess(int enable);
extern int setRemoteAccess(int enable);
extern int get_ssdk_mib_statistics(int index, char *name);
extern void getSSIStats(char *p, char *key, char *value);
extern int _get_endporint_5g_enable();
extern int _get_endporint_24g_enable();
extern int _get_endporint_5g_profile_status(char *value);
extern int _get_endporint_24g_profile_status(char *value);
extern int getRouterIPv4Number();
extern void getRouterIPv4Option(char *key, char *value, char *option);
extern int isStaticRoute(char *key);
extern int rewriteRoutingmapping();
extern int run_portmaping_entry();
extern int getPortmappingEntry(char *value, char *key);
extern void restartTR069CWMP();
extern void getMAPTInfo(char *value, char *key);
extern int getDHCPv6ClientLinkStatus();
extern int getDHCPv6ServerPoolStatus();
extern int getIPv6Enable();
extern int isValidIP(char *buf);
extern int isValidNetmask(char *buf);
extern int isValidMac(char *buf);
extern int get_Device_DHCPv4_Server_Option_num();
extern int get_NeighboringWiFi_info();
extern int set_dhcp_option_force();
extern void getManagementServerManageableDeviceInfo(char *filename, char *key, char *value);
extern void changedSecondsToDateTime(long int seconds, char *datetype);
extern int get_DynamicDNS_Server(char *value);
extern int set_DynamicDNS_Server(char *value);
extern void set_udpecho();

#endif

